package com.bwie.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.mapper.ProdMapper;
import com.bwie.pojo.Prod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Author: TaoShiHao
 * @Date: 2025/5/29 16:04
 * @Description:
 **/
@Component
@Slf4j
public class ProdDownTask {

    @Autowired
    ProdMapper prodMapper;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void prodDownTask(){
        log.info("开始执行商品下架任务");

        //定时下架状态 并且处于上架状态
        List<Prod> prodList = prodMapper.selectList(
                new QueryWrapper<Prod>().lambda().eq(Prod::getDownType, 1).eq(Prod::getProdStatus, 1).le(Prod::getDownTime, new Date())
        );
        log.info("待下架商品数量:{}",+prodList.size());
        for (Prod prod : prodList) {
            prod.setProdStatus(0);
            prodMapper.updateById(prod);
        }

        log.info("商品下架任务执行完毕----------------");
    }
}
